//
//  RadioHomeViewController.m
//  HuLaQuan
//
//  Created by hok on 1/16/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "RadioHomeViewController.h"


//Cells
#import "RadioHomeCell.h"

@interface RadioHomeViewController ()

@property (weak,nonatomic) IBOutlet UIView *topView;

@property (weak, nonatomic) IBOutlet UICollectionView *functionItemsView;
@property (strong, nonatomic) NSArray *items;

@end

static NSString * const RadioHomeCellIdentifier = @"RadioHomeCell";

@implementation RadioHomeViewController

- (NSArray *)items
{
    if(!_items) _items=[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"RadioHomeItems" ofType:@"plist"]];
    return _items;
}

- (void)setupUI
{
    self.title = @"FM952";
    
    [self setupNavBackButton];
    
    [self.functionItemsView registerNib:[RadioHomeCell nib] forCellWithReuseIdentifier:RadioHomeCellIdentifier];
    self.functionItemsView.backgroundColor = UIColorFromRGBA(0x222535, 1.0);
    
    self.view.backgroundColor = UIColorFromRGBA(0x222535, 1.0);
    
    
    
}

#pragma mark - UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.items.count;
    
    
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([collectionView isEqual:self.functionItemsView]) {
        RadioHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:RadioHomeCellIdentifier forIndexPath:indexPath];
        // [cell sizeToFit];
        
        
        
        cell.indexPath = indexPath;
        cell.itemTitle.text = self.items[indexPath.row][@"title"];
        cell.itemImageName = self.items[indexPath.row][@"image"];
        
        
        
        // //NSLog(@"booj %@ %d %@",self.items[indexPath.row][@"title"],indexPath.row, self.items[indexPath.row][@"image"]);
        /*   if ([self.items[indexPath.row][@"title"] isEqualToString:@"待审核"]) {
         if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"UserUncheckedOrder"] boolValue] ) {
         cell.redAlertPointView.hidden = NO;
         }else{
         cell.redAlertPointView.hidden = YES;
         }
         
         }
         if ([self.items[indexPath.row][@"title"] isEqualToString:@"预约记录"])
         {
         if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"UserUncheckedBigOrder"] boolValue] ) {
         cell.redAlertPointView.hidden = NO;
         }else{
         cell.redAlertPointView.hidden = YES;
         }
         }*/
        
        return cell;
    }
    
    return nil;
    
}
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.functionItemsView.bounds.size.width /kRadioHomeCellRowNumber, ceilf( self.functionItemsView.bounds.size.height/3));
    
    
}
//定义每个UICollectionView 的间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
#pragma mark - UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
   // NSLog(@"select %ld",indexPath.row);
    
//    [self performSegueWithIdentifier:@"ShowRadioPlayerViewController" sender:self];
    switch (indexPath.row) {
        case 0:
            [self performSegueWithIdentifier:@"ShowRadioPlayerViewController" sender:self];
            break;
        case 1:
            [self performSegueWithIdentifier:@"ShowDownLoadController" sender:self];
            break;
//        case 2:
//            [self performSegueWithIdentifier:@"ShowSmartTerminalViewController" sender:self];
//            break;
//        case 3:
//            [self performSegueWithIdentifier:@"ShowConvenientPayViewController" sender:self];
//            break;
        case 4:
            [self performSegueWithIdentifier:@"ShowLostPropertyViewController" sender:self];
            break;
        case 5:
            [self performSegueWithIdentifier:@"showHuLaQuanMapController" sender:self];
            break;
        default:
            break;
    }
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
